<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数组中的重复数字</title>
</head>
<body>
    
    <script>
        
        {

            // 数组中的重复数字

            let ary = [2,3,4,5,2];

            Array.prototype.repeatEle = function () {
                let obj = {};
                let ary = [];
                for(let i=0;i<this.length;i++){
                    let ele = this[i];
                    if(!obj[ele]){
                        obj[ele] = 1;
                        continue;
                    }
                    obj[ele]++;
                }
                console.log(obj);
                for (const key in obj) {
                    if (obj.hasOwnProperty(key)) {
                        const element = obj[key];
                        if(element>1){
                            ary.push(key);
                        }
                    }
                }
                return ary;
            }

            console.log(ary.repeatEle());

        }
    
    </script>

</body>
</html>